package cate.game.rank.h;

import cate.common.table.d.GDCamp;
import cate.game.GameBody;
import cate.game.role.Role;
import cate.game.role.bag.hero.Hero;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class CampHeroPowerHandlers {
    public final Map<Byte, CampHeroPowerHandler> handlers = new HashMap<>();

    public Collection<CampHeroPowerHandler> getHandlers() {
        return handlers.values();
    }

    public void initialize(GameBody game){
        byte[] camps = GDCamp.Type.getAllCamps(false);
        for(byte camp : camps){
            CampHeroPowerHandler handler = new CampHeroPowerHandler(camp);
            handler.initialize(game);
            handlers.put(camp, handler);
        }
    }

    public void record(Role role, Hero hero, long power) {
        CampHeroPowerHandler handler = handlers.get(hero.getTpl(role.getGame()).camp);
        if(handler != null){
            handler.record(role, hero, power);
        }
    }

    public void updateRole(Role role){
        handlers.values().forEach(e -> e.updateRole(role));
    }

    public void forceSave(){
        handlers.values().forEach(RankHandler::forceSave);
    }
}
